num = int(input())
if len(str(num)) < 4:
    print(0)
else:
    n1 = num
    n2 = num // 1000
    n3 = num // 100
    n4 = num // 10
    n5 = num % 1000
    n6 = num % 10
    n7 = (num // 10) % 10
    n8 = (num // 100) % 10
    sp = [n1, n2, n3, n4, n5, n6, n7, n8]
    spres = []
    fl = 0
    for i in range(0, 8):
        n = sp[i]
        d = 0
        for ch in range(2, n):
            if n % ch == 0:
                d = 1
                break
        if d == 0:
            spres.append(n)
            fl = 1
    if fl == 1 and max(spres) != 1:
        print(max(spres))
    else:
        print(0)